import java.util.Scanner;

public class Main2 {
    public static String getMaxSubStr(String a, String b) {
        char[] str1 = a.toCharArray();
        char[] str2 = b.toCharArray();
        //起始位置
        int start = 0;
        int maxLen = 0;
        int[][] maxSubLen = new int[str1.length + 1][str2.length + 1];
        for (int i = 1; i <= str1.length; i++) {
            for (int j = 1; j <= str2.length; j++) {
                //如果第i个字符和第j个字符相等,则进行累加
                if (str1[i - 1] == str2[j - 1]) {
                    maxSubLen[i][j] = maxSubLen[i - 1][j - 1] + 1;
                    if (maxLen < maxSubLen[i][j]) {
                        maxLen = maxSubLen[i][j];
                        start = i - maxLen;
                    }
                }
            }
        }
        return a.substring(start, start + maxLen);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String a = scanner.next();
        String b = scanner.next();
        if (a.length() < b.length()) {
            System.out.println(getMaxSubStr(a, b));
        } else {
            System.out.println(getMaxSubStr(b, a));
        }


    }
}
